package org.ws.edu.task1.qizer;

import org.ws.edu.task1.ICalculator;

/**
 * Created by IntelliJ IDEA.
 * User: qizer
 * Date: 29.09.11
 * Time: 10:14
 * It's work!
 */

public class CalculatorQ implements ICalculator {

	private static final char SUM = '+';
	private static final char SUBTR = '-';
	private static final char MULT = '*';
	private static final char DIV = '/';
	private static final char POW = '^';
	private static final char FACT = '!';

	double calculat(final double a, final double b, final char zn) {
		switch (zn) {
			case SUM:
				return sumD(a, b);
			case SUBTR:
				return subtr(a, b);
			case MULT:
				return mult(a, b);
			case DIV:
				return div(a, b);
			case POW:
				return mpow(a, b);
			case FACT:
				return factorialD(a);
		}
		return 0;
	}

	@Override
	public int sum(int a1, int b1) {
		return a1 + b1;  //To change body of implemented methods use File | Settings | File Templates.
	}

	public double sumD(double a1, double b1) {
		return a1 + b1;
	}

	public double subtr(double a1, double b1) {
		return a1 - b1;
	}

	public double mult(double a1, double b1) {
		return a1 * b1;
	}

	public double div(double a1, double b1) {
		return a1 / b1;
	}

	public double mpow(double a1, double b1) {
		return Math.pow(a1, b1);
	}

	@Override
	public long factorial(int n) {
		long a1 = 0;
		for (int i = 1; i < n; i++) a1 *= a1;
		return a1;
	}

	public double factorialD(double n) {
		if (n < 2) return 1;
		else return n * factorialD(n - 1);
	}
}